package com.ruoyi.project.channel.vwIncomeDayStat.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.vwIncomeDayStat.domain.VwIncomeDayStat;
import com.ruoyi.project.channel.vwIncomeDayStat.service.IVwIncomeDayStatService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * VIEW信息操作处理
 * 
 * @author CAIN
 * @date 2021-02-06
 */
@Controller
@RequestMapping("/channel/vwIncomeDayStat")
public class VwIncomeDayStatController extends BaseController
{
    private String prefix = "channel/vwIncomeDayStat";
	
	@Autowired
	private IVwIncomeDayStatService vwIncomeDayStatService;
	
	@RequiresPermissions("channel:vwIncomeDayStat:view")
	@GetMapping()
	public String vwIncomeDayStat()
	{
	    return prefix + "/vwIncomeDayStat";
	}
	
	/**
	 * 查询VIEW列表
	 */
	@RequiresPermissions("channel:vwIncomeDayStat:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(VwIncomeDayStat vwIncomeDayStat)
	{
		startPage();
        List<VwIncomeDayStat> list = vwIncomeDayStatService.selectVwIncomeDayStatList(vwIncomeDayStat);
		return getDataTable(list);
	}

	@PostMapping("/userTodayStat")
	@ResponseBody
	public AjaxResult userTodayStat()
	{
		User user = ShiroUtils.getSysUser();
		VwIncomeDayStat vwIncomeDayStat = new VwIncomeDayStat();
		vwIncomeDayStat.setUserId(user.getUserId());
		vwIncomeDayStat.setUpdateTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		List<VwIncomeDayStat> list = vwIncomeDayStatService.selectVwIncomeDayStatList(vwIncomeDayStat);
		return AjaxResult.success("success", list);
	}
	
	/**
	 * 导出VIEW列表
	 */
	@RequiresPermissions("channel:vwIncomeDayStat:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VwIncomeDayStat vwIncomeDayStat)
    {
    	List<VwIncomeDayStat> list = vwIncomeDayStatService.selectVwIncomeDayStatList(vwIncomeDayStat);
        ExcelUtil<VwIncomeDayStat> util = new ExcelUtil<VwIncomeDayStat>(VwIncomeDayStat.class);
        return util.exportExcel(list, "vwIncomeDayStat");
    }
	
	/**
	 * 新增VIEW
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存VIEW
	 */
	@RequiresPermissions("channel:vwIncomeDayStat:add")
	@Log(title = "VIEW", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(VwIncomeDayStat vwIncomeDayStat)
	{		
		return toAjax(vwIncomeDayStatService.insertVwIncomeDayStat(vwIncomeDayStat));
	}

	/**
	 * 修改VIEW
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
	{
		VwIncomeDayStat vwIncomeDayStat = vwIncomeDayStatService.selectVwIncomeDayStatById(userId);
		mmap.put("vwIncomeDayStat", vwIncomeDayStat);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存VIEW
	 */
	@RequiresPermissions("channel:vwIncomeDayStat:edit")
	@Log(title = "VIEW", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(VwIncomeDayStat vwIncomeDayStat)
	{		
		return toAjax(vwIncomeDayStatService.updateVwIncomeDayStat(vwIncomeDayStat));
	}
	
	/**
	 * 删除VIEW
	 */
	@RequiresPermissions("channel:vwIncomeDayStat:remove")
	@Log(title = "VIEW", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(vwIncomeDayStatService.deleteVwIncomeDayStatByIds(ids));
	}
	
}
